package com.example.hrsystem.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;
import com.example.hrsystem.model.DailyAttendanceRecord;
import java.util.Date;
import java.util.List;

@Dao
public interface DailyAttendanceDao {
    
    /**
     * 插入一条打卡记录
     */
    @Insert
    void insert(DailyAttendanceRecord record);
    
    /**
     * 更新打卡记录
     */
    @Update
    void update(DailyAttendanceRecord record);
    
    /**
     * 根据ID删除打卡记录
     */
    @Query("DELETE FROM daily_attendance_records WHERE id = :id")
    void deleteById(int id);
    
    /**
 * 获取指定员工在指定日期范围内的打卡记录
 */
@Query("SELECT * FROM daily_attendance_records WHERE employeeId = :employeeId AND date BETWEEN :startDate AND :endDate ORDER BY date DESC")
LiveData<List<DailyAttendanceRecord>> getDailyAttendanceRecordsByDateRange(int employeeId, Date startDate, Date endDate);

/**
 * 获取指定员工在指定日期范围内的打卡记录（同步方式）
 */
@Query("SELECT * FROM daily_attendance_records WHERE employeeId = :employeeId AND date BETWEEN :startDate AND :endDate ORDER BY date DESC")
List<DailyAttendanceRecord> getDailyAttendanceRecordsByDateRangeSync(int employeeId, Date startDate, Date endDate);

/**
 * 获取指定员工在指定日期的打卡记录
 */
@Query("SELECT * FROM daily_attendance_records WHERE employeeId = :employeeId AND date = :date LIMIT 1")
DailyAttendanceRecord getDailyAttendanceRecordByDate(int employeeId, Date date);

/**
 * 获取指定员工在指定日期范围内的打卡记录（支持String类型employeeId）
 */
@Query("SELECT * FROM daily_attendance_records WHERE employeeId = :employeeId AND date BETWEEN :startDate AND :endDate ORDER BY date DESC")
LiveData<List<DailyAttendanceRecord>> getDailyAttendanceRecordsByDateRange(String employeeId, Date startDate, Date endDate);

/**
 * 获取指定员工在指定日期范围内的打卡记录（同步方式，支持String类型employeeId）
 */
@Query("SELECT * FROM daily_attendance_records WHERE employeeId = :employeeId AND date BETWEEN :startDate AND :endDate ORDER BY date DESC")
List<DailyAttendanceRecord> getDailyAttendanceRecordsByDateRangeSync(String employeeId, Date startDate, Date endDate);

/**
 * 获取指定员工在指定日期的打卡记录（支持String类型employeeId）
 */
@Query("SELECT * FROM daily_attendance_records WHERE employeeId = :employeeId AND date = :date LIMIT 1")
DailyAttendanceRecord getDailyAttendanceRecordByDate(String employeeId, Date date);
    
    /**
     * 获取所有打卡记录
     */
    @Query("SELECT * FROM daily_attendance_records")
    LiveData<List<DailyAttendanceRecord>> getAllDailyAttendanceRecords();
}